#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <functional>
#include <boost/bind.hpp>
#include <boost/timer.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>

using namespace std;

int gcd(int a, int b)
{
	if( b==0 )return a;
	else return gcd(b,a%b);
}

int gcd_non_recusion(int a,int b)
{
	for(;;)
	{
		if(b==0) 
			return a;
		else
	       	{
			int t  =  a;
			a  =  b;
			b  %= t;
	        }
	}
}

struct GCD
{
	int a,b,x,y,gcd;
	friend ostream& operator<<(ostream& os, const GCD& gcd)
	{
		cout<<"gcd="<<gcd.gcd<<endl
		    <<"a="<<setfill('_')<<setw(8)<<gcd.a<<"   x="<<setw(8)<<gcd.x<<endl
		    <<"b="<<setw(8)<<gcd.b<<"   y="<<setw(8)<<gcd.y<<endl;
		return os;
	}
};

GCD& ext_gcd(GCD& gcd)
{
	if(gcd.b==0)
	{
		gcd.x = 1;
		gcd.y = 0;
		gcd.gcd = gcd.a;
		return gcd;
	}else{
		int a = gcd.a;
		int b = gcd.b;
		gcd.a = b;
		gcd.b = a%b;
		ext_gcd(gcd);
		gcd.a = a;
		gcd.b = b;
		int x = gcd.x;
		gcd.x = gcd.y;
		gcd.y = x-static_cast<int>(a/b)*gcd.y;
		return gcd;
	}
}	

int main(int argc, char** argv)
{
	if(argc != 3)
	{
		cout<<"cmd num1 num2"<<endl;
		exit(1);
	}

	int a,b;
	try{
	    a = boost::lexical_cast<int>(argv[1]);
	    b = boost::lexical_cast<int>(argv[2]);
	}catch(...){
	    cerr<<"error:arguments must be intergers."<<endl;
	    exit(1);
	}

	//int c = gcd(a,b);
	//int c = gcd_non_recusion(a,b);
	GCD gcd = {a,b,0,0,0};
	ext_gcd(gcd);
	cout<<gcd;

	return 0;
}
